package com.atjg.autocat.service;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.atjg.autocat.receiver.RestartReceiver;

public class RestartService {
    
    private AlarmManager alarmManager;
    private PendingIntent pendingIntent;

    public void setDailyRestart(Context context) {
        alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, RestartReceiver.class);
        pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
        
        // 设置每天凌晨2点重启
        long interval = AlarmManager.INTERVAL_DAY;
        long triggerAtMillis = System.currentTimeMillis() + interval;

        // 设置定时器
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, interval, pendingIntent);
    }
}